import { useUserStore } from '@/store/user'
import router from '@/router'

export function logout(before?: () => void, after?: () => void) {
    const userState = useUserStore()
    before && before()
    // 1、清除token
    localStorage.removeItem("token")
    // 2、清空动态路由
    userState.routes.forEach(item => router.removeRoute(item.name))
    // 3、清除pinia
    userState.username = "",
    userState.menus = []
    // 4、跳转
    router.push("/login")
    //  5、提示
    after && after()
}